import TestItem from '../../TestItem';
import { Logger } from '../../engine/Logger';
import UIManager from '../../engine/UIManager';
import ViewBase from '../../engine/ViewBase';
import { WechatSdkManager } from '../../sdk/WechatSdkManager';
import { AudioHelper } from '../audio/AudioHelper';
import { ViewConfig } from '../config/ViewConfig';
import { MjWeaveItem } from '../model/MjWeaveItem';
import { UIHelper } from '../util/UIHelper';
import { HaoEncrypt } from '../../engine/HaoEncrypt';
import RandomUtil from '../../engine/RandomUtil';
import Uint8ArrayHelper from '../../engine/Uint8ArrayHelper';
const { ccclass, property } = cc._decorator;

@ccclass
export class ViewLogin extends ViewBase {

    private btnWechat: cc.Node
    private btnAccount: cc.Node;
    private actionNode: cc.Node

    onEnable() {
        super.onEnable()
        AudioHelper.playBGM()

        // this.actionNode = this.findChild(this.node, "actionNode")
        // this.actionNode.active = false
        // this.scheduleOnce(()=>{
        // }, 5)
        let controlUI: cc.Node = this.findChild(this.node, "controlUI")
        this.btnWechat = this.findChild(controlUI, "btnWechat")
        UIHelper.onAddEvent(this.btnWechat, () => {

            // let sdfd = RandomUtil.nextInt(1, 6)
            // Logger.log("sdfd===", sdfd)

            // for(let i=0; i<1000; i++){
            //     let dfd = Uint8ArrayHelper.randomChinese(RandomUtil.nextInt(1, 4))
            //     Logger.log("dfd=", i, dfd)
            // }
            // WechatSdkManager.instance.login()
            // let myHandList: Array<number> = [
            //     // 0x13, 0x14, 0x15,0x18,0x18,0x18,0x26,0x26,0x31,0x31,0x31,0x35,0x35
            //     // 0x11, 0x11, 0x12, 0x13, 0x16, 0x16, 0x16, 0x45, 0x45, 0x45

            //     // 0x12, 0x13, 0x13,0x15,0x15,0x16,0x16,0x19,0x19,0x41,0x41,0x44,0x44
            //     // 0x13, 0x13, 0x31, 0x31, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
            //     0x17,0x17,0x17,0x13,0x13,0x13,
            // ]

            // let mjWeaveList: Array<MjWeaveItem> = [
            //     new MjWeaveItem(MjWeaveItem.Weave_Type.Gang, 0, 0, 0x16, [0x16, 0x16, 0x16]),
            //     new MjWeaveItem(MjWeaveItem.Weave_Type.Gang, 0, 0, 0x24, [0x24, 0x24, 0x24])
            // ]


            // // huanghua_mj_Manager.instance.checkJiaoHuList(myHandList, mjWeaveList)
            // let resultList = huanghua_mj_Manager.instance.get_Majiang_type(0x34, myHandList, mjWeaveList, true)
            // let resultList = huanghua_mj_Manager.instance.checkJiaoHuList(myHandList, mjWeaveList)

            // Logger.log("resultList=", resultList)

            UIManager.instance.showView(ViewConfig.viewConfig.ViewRollingLottery, () => {
            })

        })
        this.btnAccount = this.findChild(controlUI, "btnAccount")
        // if (cc.sys.isNative) {
        //     this.btnAccount.active = false
        // }
        // else {
        //     this.btnAccount.active = true
        // }
        UIHelper.onAddEvent(this.btnAccount, () => {
            // UIManager.instance.closeAllView()
            // UIManager.instance.showView(ViewConfig.viewConfig.ViewHall)
            UIManager.instance.showView(ViewConfig.viewConfig.ViewAccount, () => {
            })
        })


    }

    refreshItem(node: cc.Node, index: number) {
        Logger.log("refreshItem==", node, index)
        let item: TestItem = node.getComponent(TestItem);
        item.refresh(index);
    }


    protected update(dt: number): void {
        // if(!this.actionNode.active){
        //     this.actionNode.active = true
        //     for(let i=0; i<this.actionNode.childrenCount; i++){
        //         this.actionNode.children[i].active = false
        //         this.actionNode.children[i].active = true
        //         if(i == this.actionNode.childrenCount-1){
        //             // this.actionNode.children[i].children[0].getComponent(sp.Skeleton).setAnimation(0, "guo", true)
        //         }
        //     }
        // }
    }
}

